package com.bjsxt.commu1;

/**
 * 测试类
 */
public class Test {

    public static void main(String[] args) {

        //保证生产者和消费者之间，使用同一个工厂对象
        ProductFactory factory = new ProductFactory();

        //创建10个生产者线程并启动最好使用notifyAll，防止唤醒到
        Runnable produceRunnable = new ProduceRunnable(factory);
        for (int i = 1; i <= 10; i++) {
            new Thread(produceRunnable, "生产者" + i).start();
        }

        //创建20个消费者线程并启动
        Runnable consumeRunnable = new ConsumeRunnable(factory);
        for (int i = 1; i <= 20; i++) {
            new Thread(consumeRunnable, "消费者" + i).start();
        }

    }
}
